import Axios from 'axios'
const Api = Axios.create({
    baseURL: 'https://mpsurvey.chanel.com.cn',//process.env.NODE_ENV === 'development' ? 'https://k11openingparty.chanel.com.cn' : '/',
    // timeout: 1000,
    headers: {
        'Content-Type': 'application/json; charset=utf-8',
        'Access-Control-Allow-Origin': '*'
    }
});
const errTip = {
    "10001": "参数错误",
    "10002": "手机号已存在",
    "10003": "人数超出限制",
    "10004": "用户已存在",
    "10005": "验证码错误",
    "10006": "该场次没有剩余容量",
    "10007": "非白名单用户",
    "10008": "管理员登录失败",
    "10009": "短链接错误",
    "10010": "不在白名单",
    "10012": "验证码超时",
    "10013": "验证码错误"
}
// Add a request interceptor
Api.interceptors.request.use(function (config) {
    // Do something before request is sent
    console.log('send')
    return config;
}, function (error) {
    console.log(error)
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
Api.interceptors.response.use(function (response) {
    // Do something with response data
    if (response.data.code === '00000') {
        console.log(response)
        return response.data;
    } else {
        // alert(errTip[response.data.code])
    }
    return response;
    // return response;
}, function (error) {
    // Do something with response error
    console.log(error)
    return Promise.reject(error);
});
/**
 * 接口
 */
const pre = '/mp-survey-api'
const interfaces = {
    getInfo: pre + '/mp/findAllSurvey',
    mobile: pre + '/mp/save'
}
/**
 * 
 * @param {*} data 
 */
export function getInfo(data) {
    return Api.get(interfaces.getInfo)
}

export function submitInfo(data) {
    const datas = {
        ...data
    }
    return Api.post(interfaces.mobile, datas)
}


